import _ from "lodash";
import { roomStatus } from "../enums/hotel";

/**
 * 酒店订单:房间按照地址分组
 */
export const useGetRoomByGroup = (data) => {
  const { hotel_info } = data;
  hotel_info.forEach((hotel) => {
    const { room_info } = hotel;
    const obj = _.groupBy(room_info, "address");
    const list = [];
    for (const key in obj) {
      list.push({ key, value: obj[key] });
    }
    hotel._room_info = list;
  });
  return hotel_info;
};

/**
 * 当前订单是否可申请售后退款
 * 酒店订单-当房间存在匹配中或待服务（阿姨未上门）状态的可以申请退款;
 * 房间都为服务中、待确认、已完成 只能打电话 不能填写表单申请
 */
export const useCanApply = (hotel_info) => {
  let roomTotal = 0; // 酒店房间数
  let finalTotal = 0; // 酒店不可售后的房间数
  for (const hotel of hotel_info) {
    console.log("hotel", hotel);
    const { room } = hotel;
    for (const roomItem of room) {
      const { room_info } = roomItem;
      for (const roomInfoItem of room_info) {
        const { status, worker = null } = roomInfoItem;
        roomTotal = roomTotal + 1;
        if (
          [
            roomStatus.serving,
            roomStatus.awaitComfirm,
            roomStatus.final,
          ].includes(status)
        ) {
          finalTotal = finalTotal + 1;
        }
        // // 阿姨待上门
        // const notCome =
        //   !worker ||
        //   [
        //     workerStatus.cancel,
        //     workerStatus.awaitCome,
        //     workerStatus.await,
        //   ].includes(worker.status);
        // if (status == roomStatus.finding || notCome) {
        // }
      }
    }
  }
  console.log("roomTotal", roomTotal);
  console.log("finalTotal", finalTotal);
  return roomTotal > finalTotal; // roomTotal == finalTotal && roomTotal !== 0;
};
